using System;
namespace Example_3{
    public class ExceptionClass:ApplicationException{
        public ExceptionClass(String message):base(message){
            
        }
    }    
}
//textProductCode's KeyPressEvent
private void textProductCode_KeyPress(object sender,System.Window.Forms.KeyPressEventArgs e){
    try{
        //0-9 or backspace required
        e.Handled = e.keyChar<'0' || e.KeyChar>'9';
        if(e.KeyChar == (char)8){
            e.Handled = false;
        }
        //exception
        if(e.Handled == true){
            throw new ExceptionClass("number required");
        }catch(ExceptionClass ex){
            MessageBox.Show(ex.Message);
        }
    }
}
//btn's ClickEvent
private void btnCalculate_Click(object sender,System.EventArgs e){
    try{
        if(this.textProductRate.Text.Trim()==string.Empty || this.textUnits.Text.Trim()==string.Empty){
            throw new ExceptionClass("no word inputed");
        }else{
            this.textTotalPrice.Text = Convert.ToString(convert.ToDouble(this.textProductRate.Text)*Convert.ToDouble(this.textUnits.Text));
        }
    }catch(ExceptionClass ex){
        MessageBox.Show(ex.Message);
    }catch(Exception ex){
        MessageBox.Show(ex.Message);
    }
}
//quit's ClickEvent
private void btnExit_Click(object sender,System.EventArgs e){
    this.Close();
}